package hr.dario.kosh;

import java.util.ArrayList;
import java.util.List;

import hr.dario.kosh.database.DataBaseAdapter;
import android.app.ListActivity;
import android.database.Cursor;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class LocationList extends ListActivity {

	List<String> cityNames;
	private ListView listView;
	private DataBaseAdapter mDbHelper;
	private Cursor mCursor;

	@Override
	public void onCreate(Bundle savedInstanceState) {

		super.onCreate(savedInstanceState);

		cityNames = new ArrayList<String>();

		mDbHelper = new DataBaseAdapter(this);
		mDbHelper.open();

		mCursor = mDbHelper.fetchAllInputs(DataBaseAdapter.DATABASE_TABLE_LOC);

		startManagingCursor(mCursor);

		int loc_name = mCursor.getColumnIndex(DataBaseAdapter.KEY_LOC_NAME);

		if (mCursor.moveToFirst()) {

			while (!mCursor.isAfterLast()) {

				cityNames.add(mCursor.getString(loc_name));
				mCursor.moveToNext();

			}
		}

		listView.setAdapter(new ArrayAdapter(this,
				android.R.layout.simple_list_item_1, cityNames));

		mCursor.close();

	}

}
